package com.tmc.service.inthotel.impl;

import java.text.ParseException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

import javax.xml.datatype.XMLGregorianCalendar;
import org.apache.log4j.Logger;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import com.tmc.bean.inthotel.hotel.CXLPolicies;
import com.tmc.bean.inthotel.hotel.HotelAmenities;
import com.tmc.bean.inthotel.hotel.HotelDescription;
import com.tmc.bean.inthotel.hotel.HotelImages;
import com.tmc.bean.inthotel.hotel.HotelInfo;
import com.tmc.bean.inthotel.hotel.HotelPolicies;
import com.tmc.bean.inthotel.hotel.HotelPromotionList;
import com.tmc.bean.inthotel.hotel.HotelRoomFacilities;
import com.tmc.bean.inthotel.hotel.HotelRoomTypes;
import com.tmc.bean.inthotel.hotel.HotelVoucherRemark;
import com.tmc.bean.inthotel.xml.TouricoRequestXml;
import com.tmc.dao.impl.inthotel.CXLPoliciesDaoImpl;
import com.tmc.dao.impl.inthotel.IntHotelCityDaoImpl;
import com.tmc.dao.impl.inthotel.IntHotelContinentDaoImpl;
import com.tmc.dao.impl.inthotel.IntHotelCountryDaoImpl;
import com.tmc.dao.impl.inthotel.HotelAmenitiesDaoImpl;
import com.tmc.dao.impl.inthotel.HotelDaoImpl;
import com.tmc.dao.impl.inthotel.HotelDescriptionDaoImpl;
import com.tmc.dao.impl.inthotel.HotelImagesDaoImpl;
import com.tmc.dao.impl.inthotel.HotelInfoDaoImpl;
import com.tmc.dao.impl.inthotel.HotelPoliciesDaoImpl;
import com.tmc.dao.impl.inthotel.HotelPromotionListDaoImpl;
import com.tmc.dao.impl.inthotel.HotelRoomFacilitiesDaoImpl;
import com.tmc.dao.impl.inthotel.HotelRoomTypesDaoImpl;
import com.tmc.dao.impl.inthotel.HotelVoucherRemarkDaoImpl;
import com.tmc.dao.impl.inthotel.StateDaoImpl;
import com.tmc.dao.impl.inthotel.ToCountryContinentDaoImpl;
import com.tmc.dao.impl.inthotel.ToDestinationResultDaoImpl;
import com.tmc.dao.impl.inthotel.ToHotelTblDaoImpl;
import com.tmc.entity.inthotel.CityInfo;
import com.tmc.entity.inthotel.ToActivity;
import com.tmc.entity.inthotel.ToCity;
import com.tmc.entity.inthotel.ToCitylocation;
import com.tmc.entity.inthotel.ToContinent;
import com.tmc.entity.inthotel.ToCountry;
import com.tmc.entity.inthotel.ToDestinationResult;
import com.tmc.entity.inthotel.ToHotel;
import com.tmc.entity.inthotel.ToHotelTbl;
import com.tmc.entity.inthotel.ToProvider;
import com.tmc.entity.inthotel.ToState;
import com.tmc.service.cache.CacheServiceImpl;
import com.tmc.service.inthotel.TouricoHolidayService;
import com.tmc.test.SaxHtmlTest;
import com.tmc.util.DateUtil;
import com.tmc.util.HttpUtil;
import com.tmc.util.XMLBeanUtil;
import com.tmc.util.XMLUtil;
import com.tourico.schemas.webservices.hotelv3.AmendRequest;
import com.tourico.schemas.webservices.hotelv3.BookV3Request;
import com.tourico.schemas.webservices.hotelv3.CostAmendRequest;
import com.tourico.schemas.webservices.hotelv3.SearchHotelsByDestinationIdsRequest;
import com.tourico.schemas.webservices.hotelv3.SearchHotelsByIdRequest;
import com.tourico.schemas.webservices.hotelv3.SearchRequest;
import com.tourico.webservices.CancelReservationResponse;
import com.tourico.webservices.GetCancellationFeeResponse;
import com.tourico.webservices.GetCancellationPoliciesResponse;
import com.tourico.webservices.hotelv3.ArrayOfFeature;
import com.tourico.webservices.hotelv3.ArrayOfHotelID;
import com.tourico.webservices.hotelv3.BookHotelV3Response;
import com.tourico.webservices.hotelv3.CheckAvailabilityAndPricesResponse;
import com.tourico.webservices.hotelv3.CostAmendResponse;
import com.tourico.webservices.hotelv3.DoAmendResponse;
import com.tourico.webservices.hotelv3.SearchHotelsByDestinationIdsResponse;
import com.tourico.webservices.hotelv3.SearchHotelsByIdResponse;
import com.tourico.webservices.hotelv3.SearchHotelsResponse;
import com.touricoholidays.wsdestinations._2008._08.datacontracts.ActivitiesByDestinationResponse;
import com.touricoholidays.wsdestinations._2008._08.datacontracts.Activity;
import com.touricoholidays.wsdestinations._2008._08.datacontracts.City;
import com.touricoholidays.wsdestinations._2008._08.datacontracts.CityLocation;
import com.touricoholidays.wsdestinations._2008._08.datacontracts.Continent;
import com.touricoholidays.wsdestinations._2008._08.datacontracts.Country;
import com.touricoholidays.wsdestinations._2008._08.datacontracts.Destination;
import com.touricoholidays.wsdestinations._2008._08.datacontracts.DestinationResponse;
import com.touricoholidays.wsdestinations._2008._08.datacontracts.DestinationResult;
import com.touricoholidays.wsdestinations._2008._08.datacontracts.Hotel;
import com.touricoholidays.wsdestinations._2008._08.datacontracts.HotelsByDestinationResponse;
import com.touricoholidays.wsdestinations._2008._08.datacontracts.State;
import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;

@Service
@Transactional
public class TouricoHolidayServiceImpl implements TouricoHolidayService {

	@Autowired
	private ToDestinationResultDaoImpl toDestinationResultDaoImpl;
	@Autowired
	private ToHotelTblDaoImpl toHotelTblDaoImpl;
	@Autowired
	private ToCountryContinentDaoImpl toCountryContientDaoImpl;
	@Autowired
	private IntHotelCityDaoImpl cityDaoImpl;
	@Autowired
	private HotelDaoImpl hotelDaoImpl;
	@Autowired
	private HotelVoucherRemarkDaoImpl hotelVoucherRemarkDaoImpl;
	@Autowired
	private HotelRoomTypesDaoImpl hotelRoomTypesDaoImpl;
	@Autowired
	private HotelRoomFacilitiesDaoImpl hotelRoomFacilitiesDaoImpl;
	@Autowired
	private HotelPromotionListDaoImpl hotelPromotionListDaoImpl;
	@Autowired
	private HotelPoliciesDaoImpl hotelPoliciesDaoImpl;
	@Autowired
	private HotelInfoDaoImpl hotelInfoDaoImpl;
	@Autowired 
	private HotelImagesDaoImpl hotelImagesDaoImpl;
	@Autowired
	private HotelDescriptionDaoImpl hotelDescriptionDaoImpl;
	@Autowired
	private HotelAmenitiesDaoImpl hotelAmenitiesDaoImpl;
	@Autowired
	private CXLPoliciesDaoImpl cXLPoliciesDaoImpl;
	@Autowired
	private CacheServiceImpl cache;
	@Autowired
	private IntHotelContinentDaoImpl continentDaoImpl;
	@Autowired
	private IntHotelCountryDaoImpl countryDaoImpl;
	@Autowired
	private StateDaoImpl stateDaoImpl;
	
	private static final String HOTEL_DESTINATION = "HOTEL_DESTINATION";
	private static final String DESTINATION = "DESTINATION";
	private static final String ACTIVITY_DESTINATION = "ACTIVITY_DESTINATION";
	private static final String TOURICO_DATABASE = "TOURICO_DATABASE";
	private Logger log = Logger.getLogger(TouricoHolidayServiceImpl.class);
	
	/**
	 * 查询所有州信息
	 */
	@Override
	public List<com.tmc.bean.inthotel.hotel.State> getAllState() {
		return stateDaoImpl.getAllState();
	}

	/**
	 * 批量更新州信息
	 */
	@Override
	public void updateAllState(List<com.tmc.bean.inthotel.hotel.State> states) {
		stateDaoImpl.updateAllState(states);
	}
	
	/**
	 * 查询所有国家信息
	 */
	@Override
	public List<com.tmc.bean.inthotel.hotel.Country> getAllCountry() {
		return countryDaoImpl.findAll();
	}

	/**
	 * 批量更新国家信息
	 */
	@Override
	public void updateAllCountry(
			List<com.tmc.bean.inthotel.hotel.Country> countries) {
		countryDaoImpl.updateAllCountry(countries);
	}
	
	/**
	 * 查询所有大陆信息
	 */
	@Override
	public List<com.tmc.bean.inthotel.hotel.Continent> getAllContinent() {
		return continentDaoImpl.getAllContinent();
	}

	/**
	 * 批量更新大陆信息
	 */
	@Override
	public void updateAllContinent(
			List<com.tmc.bean.inthotel.hotel.Continent> continents) {
		continentDaoImpl.update(continents);
	}
	
	public BufferedReader cvsReader(String f){
		File csv = new File(f);  // CSV文件路径
	    FileInputStream fis = null;
	    InputStreamReader isr = null;
	    BufferedReader br = null;
	    try
	    {
	    	fis = new FileInputStream(csv);
	    	isr = new InputStreamReader(fis,"GBK");
	    	//isr = new InputStreamReader(fis);
	    	br = new BufferedReader(isr);
	    } catch (FileNotFoundException e)
	    {
	        e.printStackTrace();
	    } catch (Exception e) {
			e.printStackTrace();
		}
	    return br;
	}
	
	@Override
	public void selectAndInsert(List<HotelVoucherRemark> hotelVoucherRemarks) {
		hotelDaoImpl.selectAndInsert(hotelVoucherRemarks);
	}
	
	public String loadHotelVoucherRemark(String filePath){
		List<HotelVoucherRemark> hotelVoucherRemarks = saxHotelVoucherRemarkCSVFile(filePath);
		selectAndInsert(hotelVoucherRemarks);
		/*saveAllHotelVoucherRemark(hotelVoucherRemarks);
		List<HotelRoomTypes> hotelRoomTypes = saxHotelRoomTypesCSVFile(filePath);*/
		
		return null;
	}
	
	public List<HotelVoucherRemark> saxHotelVoucherRemarkCSVFile(String f)
	{
		/*File csv = new File(f);  // CSV文件路径
	    FileInputStream fis = null;
	    InputStreamReader isr = null;
	    BufferedReader br = null;
	    List<HotelVoucherRemark> allString = new ArrayList<HotelVoucherRemark>();
	    try
	    {
	    	fis = new FileInputStream(csv);
	    	isr = new InputStreamReader(fis,"UTF-8");
	    	br = new BufferedReader(isr);
	    } catch (FileNotFoundException e)
	    {
	        e.printStackTrace();
	    } catch (Exception e) {
			e.printStackTrace();
		}*/
		List<HotelVoucherRemark> allString = new ArrayList<HotelVoucherRemark>();
		BufferedReader br = cvsReader(f);
	    String line = "";
	    String urlLine = "";
	    try {
	            while ((line = br.readLine()) != null)  //读取到的内容给line变量
	            {
	                urlLine = line;
	                boolean isNum = urlLine.contains("0")||urlLine.contains("1")||urlLine.contains("2")||urlLine.contains("3")||urlLine.contains("4")||urlLine.contains("5")||urlLine.contains("6")||urlLine.contains("7")||urlLine.contains("8")||urlLine.contains("9");
	                if(isNum){
	                	String[] strs = urlLine.split("[|]");
	                	for (int i = 0; i < strs.length; i++) {
	                		strs[i] = removeSpace(strs[i]);
	                		strs[i] = strs[i].trim();
						}
	                    HotelVoucherRemark hotelVoucherRemark = new HotelVoucherRemark();
	                    hotelVoucherRemark.setForeignId(Integer.valueOf(strs[0]));
	                    hotelVoucherRemark.setVoucherRemark(strs[1]);
	                	System.out.println(strs[0]+"--"+strs[1]);
	                	allString.add(hotelVoucherRemark);
	                }
	            }
	    } catch (IOException e)
	    {
	        e.printStackTrace();
	    }
	    return allString;
	}
	
	public String loadHotelRoomTypes(String filePath){
		List<HotelRoomTypes> hotelRoomTypes = saxHotelRoomTypesCSVFile(filePath);
		saveAllHotelRoomTypes(hotelRoomTypes);
		return null;
	}
	
	public List<HotelRoomTypes> saxHotelRoomTypesCSVFile(String f){
		List<HotelRoomTypes> allString = new ArrayList<HotelRoomTypes>();
		BufferedReader br = cvsReader(f);
	    String line = "";
	    String urlLine = "";
	    try {
	            while ((line = br.readLine()) != null)  //读取到的内容给line变量
	            {
	                urlLine = line;
	                boolean isNum = urlLine.contains("0")||urlLine.contains("1")||urlLine.contains("2")||urlLine.contains("3")||urlLine.contains("4")||urlLine.contains("5")||urlLine.contains("6")||urlLine.contains("7")||urlLine.contains("8")||urlLine.contains("9");
	                if(isNum){
	                	String[] strs = urlLine.split("[|]");
	                	for (int i = 0; i < strs.length; i++) {
	                		strs[i] = removeSpace(strs[i]);
	                		strs[i] = strs[i].trim();
						}
	                	HotelRoomTypes hotelRoomTypes = new HotelRoomTypes();
	                	if(strs[0]!=null&&!strs[0].equalsIgnoreCase("")){
	                		hotelRoomTypes.setForeignId(Integer.valueOf(strs[0]));
	                	}
	                	hotelRoomTypes.setProvider(strs[2]);
	                	
	                	hotelRoomTypes.setRoomTypeName(strs[6]);
	                	if(strs.length==12){
	                		if(!strs[3].matches("\\d+")){
	                			if(strs[4]!=null&&!strs[4].equalsIgnoreCase("")){
			                		hotelRoomTypes.setChildAge(Integer.valueOf(strs[4]));
			                	}
			                	if(strs[5]!=null&&!strs[5].equalsIgnoreCase("")){
			                		hotelRoomTypes.setHotelRoomTypeId(Integer.valueOf(strs[5]));
			                	}
			                	if(strs[6]!=null&&!strs[6].equalsIgnoreCase("")){
			                		hotelRoomTypes.setRoomId(Integer.valueOf(strs[6]));
			                	}
	                		}else{
	                			if(strs[3]!=null&&!strs[3].equalsIgnoreCase("")){
			                		hotelRoomTypes.setChildAge(Integer.valueOf(strs[3]));
			                	}
			                	if(strs[4]!=null&&!strs[4].equalsIgnoreCase("")){
			                		hotelRoomTypes.setHotelRoomTypeId(Integer.valueOf(strs[4]));
			                	}
			                	if(strs[5]!=null&&!strs[5].equalsIgnoreCase("")){
			                		hotelRoomTypes.setRoomId(Integer.valueOf(strs[5]));
			                	}
	                		}
	                		if(strs[8]!=null&&!strs[8].equalsIgnoreCase("")){
		                		hotelRoomTypes.setMaxAdults(Integer.valueOf(strs[8]));
		                	}
		                	if(strs[9]!=null&&!strs[9].equalsIgnoreCase("")){
		                		hotelRoomTypes.setMaxChild(Integer.valueOf(strs[9]));
		                	}
	                	}else{
	                		if(strs[3]!=null&&!strs[3].equalsIgnoreCase("")){
		                		hotelRoomTypes.setChildAge(Integer.valueOf(strs[3]));
		                	}
		                	if(strs[4]!=null&&!strs[4].equalsIgnoreCase("")){
		                		hotelRoomTypes.setHotelRoomTypeId(Integer.valueOf(strs[4]));
		                	}
		                	if(strs[5]!=null&&!strs[5].equalsIgnoreCase("")){
		                		hotelRoomTypes.setRoomId(Integer.valueOf(strs[5]));
		                	}
	                		if(strs[7]!=null&&!strs[7].equalsIgnoreCase("")){
		                		hotelRoomTypes.setMaxAdults(Integer.valueOf(strs[7]));
		                	}
		                	if(strs[8]!=null&&!strs[8].equalsIgnoreCase("")){
		                		hotelRoomTypes.setMaxChild(Integer.valueOf(strs[8]));
		                	}
	                	}
	                    /*hotelVoucherRemark.setForeignId(Integer.valueOf(strs[0]));
	                    hotelVoucherRemark.setVoucherRemark(strs[1]);
	                	System.out.println(strs[0]+"--"+strs[1]);*/
	                	System.out.println(hotelRoomTypes.getForeignId());
	                	allString.add(hotelRoomTypes);
	                }
	            }
	    } catch (Exception e)
	    {
	        e.printStackTrace();
	    }
	    return allString;
	}
	
	public String loadHotelRoomFacilities(String filePath){
		List<HotelRoomFacilities> hotelRoomFacilities = saxHotelRoomFacilitiesCSVFile(filePath);
		saveAllHotelRoomFacilities(hotelRoomFacilities);
		return null;
	}
	
	public List<HotelRoomFacilities> saxHotelRoomFacilitiesCSVFile(String f){
		List<HotelRoomFacilities> allString = new ArrayList<HotelRoomFacilities>();
		BufferedReader br = cvsReader(f);
	    String line = "";
	    String urlLine = "";
	    try {
	            while ((line = br.readLine()) != null)  //读取到的内容给line变量
	            {
	                urlLine = line;
	                boolean isNum = urlLine.contains("0")||urlLine.contains("1")||urlLine.contains("2")||urlLine.contains("3")||urlLine.contains("4")||urlLine.contains("5")||urlLine.contains("6")||urlLine.contains("7")||urlLine.contains("8")||urlLine.contains("9");
	                if(isNum){
	                	String[] strs = urlLine.split("[|]");
	                	for (int i = 0; i < strs.length; i++) {
	                		strs[i] = removeSpace(strs[i]);
	                		strs[i] = strs[i].trim();
						}
	                	System.out.println(strs[0]);
	                	HotelRoomFacilities hotelRoomFacilities = new HotelRoomFacilities();
	                	hotelRoomFacilities.setHotelRoomTypeId(Integer.valueOf(strs[1]));
	                	hotelRoomFacilities.setRoomId(Integer.valueOf(strs[2]));
	                	hotelRoomFacilities.setFacilityId(Integer.valueOf(strs[3]));
	                	hotelRoomFacilities.setRoomFacilityName(strs[4]);
	                	hotelRoomFacilities.setStatus(strs[6]);
	                	hotelRoomFacilities.setForeignId(Integer.valueOf(strs[0]));
	                	allString.add(hotelRoomFacilities);
	                }
	            }
	    } catch (Exception e)
	    {
	        e.printStackTrace();
	    }
	    return allString;
	}
	
	public String loadHotelPromotionList(String filePath){
		List<HotelPromotionList> hotelPromotionLists = saxHotelPromotionListCSVFile(filePath);
		saveAllHotelPromotionList(hotelPromotionLists);
		return null;
	}
	
	public List<HotelPromotionList> saxHotelPromotionListCSVFile(String f){
		List<HotelPromotionList> allString = new ArrayList<HotelPromotionList>();
		BufferedReader br = cvsReader(f);
	    String line = "";
	    String urlLine = "";
	    try {
	            while ((line = br.readLine()) != null)  //读取到的内容给line变量
	            {
	                urlLine = line;
	                boolean isNum = urlLine.contains("0")||urlLine.contains("1")||urlLine.contains("2")||urlLine.contains("3")||urlLine.contains("4")||urlLine.contains("5")||urlLine.contains("6")||urlLine.contains("7")||urlLine.contains("8")||urlLine.contains("9");
	                if(isNum){
	                	String[] strs = urlLine.split("[|]");
	                	for (int i = 0; i < strs.length; i++) {
	                		strs[i] = removeSpace(strs[i]);
	                		strs[i] = strs[i].trim();
						}
	                	System.out.println(strs[0]);
	                	HotelPromotionList hotelPromotionList = new HotelPromotionList();
	                	hotelPromotionList.setExclusiveDeal(strs[2]);
	                	hotelPromotionList.setRoomTypeName(strs[3]);
	                	hotelPromotionList.setHotelRoomTypeId(Integer.valueOf(strs[4]));
	                	hotelPromotionList.setFromDate(DateUtil.format(strs[5],"yyyy-MM-dd"));
	                	hotelPromotionList.setToDate(DateUtil.format(strs[6],"yyyy-MM-dd"));
	                	hotelPromotionList.setPromotionType(strs[7]);
	                	hotelPromotionList.setValue(strs[8]);
	                	hotelPromotionList.setRemarks(strs[9]);
	                	hotelPromotionList.setHotelCurrency(strs[10]);
	                	hotelPromotionList.setStars(strs[11]);
	                	hotelPromotionList.setForeignId(Integer.valueOf(strs[0]));
	                	allString.add(hotelPromotionList);
	                }
	            }
	    } catch (Exception e)
	    {
	        e.printStackTrace();
	    }
	    return allString;
	}
	
	public String loadHotelPolicies(String filePath){
		List<HotelPolicies> hotelPolicies = saxHotelPoliciesCSVFile(filePath);
		saveAllHotelPolicies(hotelPolicies);
		return null;
	}
	
	public List<HotelPolicies> saxHotelPoliciesCSVFile(String f){
		List<HotelPolicies> allString = new ArrayList<HotelPolicies>();
		BufferedReader br = cvsReader(f);
	    String line = "";
	    String urlLine = "";
	    try {
	            while ((line = br.readLine()) != null)  //读取到的内容给line变量
	            {
	                urlLine = line;
	                boolean isNum = urlLine.contains("0")||urlLine.contains("1")||urlLine.contains("2")||urlLine.contains("3")||urlLine.contains("4")||urlLine.contains("5")||urlLine.contains("6")||urlLine.contains("7")||urlLine.contains("8")||urlLine.contains("9");
	                if(isNum){
	                	String[] strs = urlLine.split("[|]");
	                	for (int i = 0; i < strs.length; i++) {
	                		strs[i] = removeSpace(strs[i]);
	                		strs[i] = strs[i].trim();
						}
	                	System.out.println(strs[0]);
	                	HotelPolicies hotelPolicies = new HotelPolicies();
	                	hotelPolicies.setHotelPoliciesEnUS(strs[1]);
	                	//hotelPolicies.setHotelPoliciesZhCN(strs[10]);
	                	//hotelPolicies.setForeignId(Integer.valueOf(strs[0]));
	                	allString.add(hotelPolicies);
	                }
	            }
	    } catch (Exception e)
	    {
	        e.printStackTrace();
	    }
	    return allString;
	}
	
	public String loadHotelInfo(String filePath){
		List<HotelInfo> hotelInfos = saxHotelInfoCSVFile(filePath);
		saveAllHotelInfo(hotelInfos);
		return null;
	}
	
	public List<HotelInfo> saxHotelInfoCSVFile(String f){
		List<HotelInfo> allString = new ArrayList<HotelInfo>();
		BufferedReader br = cvsReader(f);
	    String line = "";
	    String urlLine = "";
	    try {
	            while ((line = br.readLine()) != null)  ////读取到的内容给line变量
	            {
	                urlLine = line;
	                boolean isNum = urlLine.contains("0")||urlLine.contains("1")||urlLine.contains("2")||urlLine.contains("3")||urlLine.contains("4")||urlLine.contains("5")||urlLine.contains("6")||urlLine.contains("7")||urlLine.contains("8")||urlLine.contains("9");
	                if(isNum){
	                	String[] strs = urlLine.split("[|]");
	                	for (int i = 0; i < strs.length; i++) {
	                		strs[i] = removeSpace(strs[i]);
	                		strs[i] = strs[i].trim();
						}
	                	System.out.println(strs[0]);
	                	HotelInfo hotelInfo = new HotelInfo();
	                	hotelInfo.setExclusiveDeal(strs[2]);
	                	if(strs[3]!=null&&!strs[3].equalsIgnoreCase("")){
	                		hotelInfo.setCheckInHour(Integer.valueOf(strs[3]));
	                	}
	                	if(strs[4]!=null&&!strs[4].equalsIgnoreCase("")){
	                		hotelInfo.setCheckOutHour(Integer.valueOf(strs[4]));
	                	}
	                	if(strs[5]!=null&&!strs[5].equalsIgnoreCase("")){
	                		hotelInfo.setTotalRoomsInHotel(Integer.valueOf(strs[5]));
	                	}
	                	hotelInfo.setThumbnailPath(strs[6]);
	                	hotelInfo.setShortDescription(strs[7]);
	                	hotelInfo.setHotelCurrency(strs[8]);
	                	hotelInfo.setStars(strs[9]);
	                	hotelInfo.setAddress(strs[10]);
	                	hotelInfo.setAddressZip(strs[11]);
	                	hotelInfo.setPhone(strs[24]);
	                	hotelInfo.setFax(strs[25]);
	                	hotelInfo.setNearestAirportIATACode(strs[26]);
	                	hotelInfo.setRefDirection(strs[27]);
	                	hotelInfo.setRefPointDist(strs[28]);
	                	hotelInfo.setDistUnit(strs[29]);
	                	hotelInfo.setStatus(strs[31]);
	                	hotelInfo.setForeignId(Integer.valueOf(strs[0]));
	                	allString.add(hotelInfo);
	                }
	            }
	    } catch (Exception e)
	    {
	        e.printStackTrace();
	    }
	    return allString;
	}
	
	public String loadHotelImages(String filePath){
		List<HotelImages> hotelImages = saxHotelImagesCSVFile(filePath);
		saveAllHotelImages(hotelImages);
		return null;
	}
	
	public List<HotelImages> saxHotelImagesCSVFile(String f){
		List<HotelImages> allString = new ArrayList<HotelImages>();
		BufferedReader br = cvsReader(f);
	    String line = "";
	    String urlLine = "";
	    try {
	            while ((line = br.readLine()) != null)  //读取到的内容给line变量
	            {
	                urlLine = line;
	                boolean isNum = urlLine.contains("0")||urlLine.contains("1")||urlLine.contains("2")||urlLine.contains("3")||urlLine.contains("4")||urlLine.contains("5")||urlLine.contains("6")||urlLine.contains("7")||urlLine.contains("8")||urlLine.contains("9");
	                if(isNum){
	                	String[] strs = urlLine.split("[|]");
	                	for (int i = 0; i < strs.length; i++) {
	                		strs[i] = removeSpace(strs[i]);
	                		strs[i] = strs[i].trim();
						}
	                	System.out.println(strs[0]);
	                	HotelImages hotelImages = new HotelImages();
	                	hotelImages.setImageUrl(strs[2]);
	                	if(strs[3].matches("^-?\\d+$")){
	                		hotelImages.setImageTypeId(Integer.valueOf(strs[3]));
	                	}
	                	hotelImages.setImageTypeName(strs[4]);
	                	hotelImages.setIsThumbnail(strs[5]);
	                	hotelImages.setBigThumbnail(strs[6]);
	                	hotelImages.setStatus(strs[8]);
	                	if(strs[0].matches("^-?\\d+$")){
	                		hotelImages.setForeignId(Integer.valueOf(strs[0]));
	                	}
	                	allString.add(hotelImages);
	                }
	            }
	    } catch (Exception e)
	    {
	        e.printStackTrace();
	    }
	    return allString;
	}
	
	public String loadHotelDescription(String filePath){
		List<HotelDescription> allString = saxHotelDescriptionCSVFile(filePath);
		saveAllHotelDescription(allString);
		return null;
	}
	
	public List<HotelDescription> saxHotelDescriptionCSVFile(String f){
		List<HotelDescription> allString = new ArrayList<HotelDescription>();
		BufferedReader br = cvsReader(f);
	    String line = "";
	    String urlLine = "";
	    try {
	            while ((line = br.readLine()) != null)  //读取到的内容给line变量
	            {
	                urlLine = line;
	                boolean isNum = urlLine.contains("0")||urlLine.contains("1")||urlLine.contains("2")||urlLine.contains("3")||urlLine.contains("4")||urlLine.contains("5")||urlLine.contains("6")||urlLine.contains("7")||urlLine.contains("8")||urlLine.contains("9");
	                if(isNum){
	                	String[] strs = urlLine.split("[|]");
	                	for (int i = 0; i < strs.length; i++) {
	                		strs[i] = removeSpace(strs[i]);
	                		strs[i] = strs[i].trim();
						}
	                	System.out.println(strs[0]);
	                	HotelDescription hotelDescription = new HotelDescription();
	                	hotelDescription.setShortDescriptionEnUS(strs[1]);
	                	hotelDescription.setLongDescriptionEnUS(strs[2]);
	                	hotelDescription.setStatus(strs[4]);
	                	hotelDescription.setForeignId(Integer.valueOf(strs[0]));
	                	allString.add(hotelDescription);
	                }
	            }
	    } catch (Exception e)
	    {
	        e.printStackTrace();
	    }
	    return allString;
	}
	
	public String loadHotelAmenities(String filePath){
		List<HotelAmenities> allString = saxHotelAmenitiesCSVFile(filePath);
		saveAllHotelAmenities(allString);
		return null;
	}
	
	public List<HotelAmenities> saxHotelAmenitiesCSVFile(String f){
		List<HotelAmenities> allString = new ArrayList<HotelAmenities>();
		BufferedReader br = cvsReader(f);
	    String line = "";
	    String urlLine = "";
	    try {
	            while ((line = br.readLine()) != null)  //读取到的内容给line变量
	            {
	                urlLine = line;
	                boolean isNum = urlLine.contains("0")||urlLine.contains("1")||urlLine.contains("2")||urlLine.contains("3")||urlLine.contains("4")||urlLine.contains("5")||urlLine.contains("6")||urlLine.contains("7")||urlLine.contains("8")||urlLine.contains("9");
	                if(isNum){
	                	String[] strs = urlLine.split("[|]");
	                	for (int i = 0; i < strs.length; i++) {
	                		strs[i] = removeSpace(strs[i]);
	                		strs[i] = strs[i].trim();
						}
	                	System.out.println(strs[0]);
	                	HotelAmenities hotelAmenities = new HotelAmenities();
	                	hotelAmenities.setStatus(strs[0]);
	                	if(strs.length==7){
	                		if(strs[3]!=null&&!strs[3].equalsIgnoreCase("")){
	                			hotelAmenities.setAmenityId(Integer.valueOf(strs[3]));
	                			hotelAmenities.setAmenityName(strs[4]);
	                		}
	                	}else{
	                		hotelAmenities.setAmenityId(Integer.valueOf(strs[2]));
	                		hotelAmenities.setAmenityName(strs[3]);
	                	}
	                	allString.add(hotelAmenities);
	                }
	            }
	    } catch (Exception e)
	    {
	        e.printStackTrace();
	    }
	    return allString;
	}
	
	public String loadCXLPolicies(String filePath){
		List<CXLPolicies> allString = saxCXLPoliciesCSVFile(filePath);
		saveAllCXLPolicies(allString);
		return null;
	}
	
	public List<CXLPolicies> saxCXLPoliciesCSVFile(String f){
		List<CXLPolicies> allString = new ArrayList<CXLPolicies>();
		BufferedReader br = cvsReader(f);
	    String line = "";
	    String urlLine = "";
	    try {
	            while ((line = br.readLine()) != null)  //读取到的内容给line变量
	            {
	                urlLine = line;
	                boolean isNum = urlLine.contains("0")||urlLine.contains("1")||urlLine.contains("2")||urlLine.contains("3")||urlLine.contains("4")||urlLine.contains("5")||urlLine.contains("6")||urlLine.contains("7")||urlLine.contains("8")||urlLine.contains("9");
	                if(isNum){
	                	String[] strs = urlLine.split("[|]");
	                	for (int i = 0; i < strs.length; i++) {
	                		strs[i] = removeSpace(strs[i]);
	                		strs[i] = strs[i].trim();
						}
	                	System.out.println(strs[0]);
	                	CXLPolicies cXLPolicies = new CXLPolicies();
	                	cXLPolicies.setRoomTypeName(strs[2]);
	                	if(strs[3]!=null&&strs[3].equalsIgnoreCase("")){
	                		cXLPolicies.setHotelRoomTypeId(Integer.valueOf(strs[3]));
	                	}
	                	cXLPolicies.setIsDefault(strs[4]);
	                	cXLPolicies.setIsNoShow(strs[5]);
	                	cXLPolicies.setDays(strs[6]);
	                	cXLPolicies.setRuleDescription(strs[7]);
	                	cXLPolicies.setFeeValue(strs[8]);
	                	cXLPolicies.setFee(strs[9]);
	                	cXLPolicies.setCityName(strs[10]);
	                	cXLPolicies.setCountryCode(strs[11]);
	                	if(strs[12]!=null&&!strs[12].equalsIgnoreCase("")){
	                		cXLPolicies.setFromDate(DateUtil.format(strs[12],"yyyy-MM-dd"));
	                	}
	                	if(strs[13]!=null&&!strs[13].equalsIgnoreCase("")){
	                		cXLPolicies.setToDate(DateUtil.format(strs[13],"yyyy-MM-dd"));
	                	}
	                	cXLPolicies.setCurrency(strs[14]);
	                	cXLPolicies.setForeignId(Integer.valueOf(strs[0]));
	                	allString.add(cXLPolicies);
	                }
	            }
	    } catch (Exception e)
	    {
	        e.printStackTrace();
	    }
	    return allString;
	}
	
	@Override
	public void saveAllHotelVoucherRemark(
			List<HotelVoucherRemark> hotelVoucherRemark) {
		hotelVoucherRemarkDaoImpl.saveAllHotelVoucherRemark(hotelVoucherRemark);
	}
    
	@Override
	public void updateAllHotelVoucherRemark(
			List<HotelVoucherRemark> hotelVoucherRemark) {
		hotelVoucherRemarkDaoImpl.updateAllHotelVoucherRemark(hotelVoucherRemark);	
	}
    
	@Override
	public List<HotelVoucherRemark> findAllHotelVoucherRemark() {
		return hotelVoucherRemarkDaoImpl.findAllHotelVoucherRemark();
	}
    
	@Override
	public void saveAllHotelRoomTypes(List<HotelRoomTypes> hotelRoomTypes) {
		hotelRoomTypesDaoImpl.saveAllHotelRoomTypes(hotelRoomTypes);
	}

	@Override
	public void updateAllHotelRoomTypes(List<HotelRoomTypes> hotelRoomTypes) {
		hotelRoomTypesDaoImpl.updateAllHotelRoomTypes(hotelRoomTypes);
	}

	@Override
	public List<HotelRoomTypes> findAllHotelRoomTypes() {
		return hotelRoomTypesDaoImpl.findAllHotelRoomTypes();
	}

	@Override
	public void saveAllHotelRoomFacilities(
			List<HotelRoomFacilities> hotelRoomFacilities) {
		hotelRoomFacilitiesDaoImpl.saveAllHotelRoomFacilities(hotelRoomFacilities);
		
	}

	@Override
	public void updateAllHotelRoomFacilities(
			List<HotelRoomFacilities> hotelRoomFacilities) {
		hotelRoomFacilitiesDaoImpl.updateAllHotelRoomFacilities(hotelRoomFacilities);
	}

	@Override
	public List<HotelRoomFacilities> findAllHotelRoomFacilities() {
		return hotelRoomFacilitiesDaoImpl.findAllHotelRoomFacilities();
	}

	@Override
	public void saveAllHotelPromotionList(
			List<HotelPromotionList> hotelPromotionList) {
		hotelPromotionListDaoImpl.saveAllHotelPromotionList(hotelPromotionList);
	}

	@Override
	public void updateAllHotelPromotionList(
			List<HotelPromotionList> hotelPromotionList) {
		hotelPromotionListDaoImpl.updateAllHotelPromotionList(hotelPromotionList);
	}

	@Override
	public List<HotelPromotionList> findAllHotelPromotionList() {
		return hotelPromotionListDaoImpl.findAllHotelPromotionList();
	}

	@Override
	public void saveAllHotelPolicies(List<HotelPolicies> hotelPolicies) {
		hotelPoliciesDaoImpl.saveAllHotelPolicies(hotelPolicies);
		
	}

	@Override
	public void updateAllHotelPolicies(List<HotelPolicies> hotelPolicies) {
		hotelPoliciesDaoImpl.updateAllHotelPolicies(hotelPolicies);
		
	}

	@Override
	public List<HotelPolicies> findAllHotelPolicies() {
		return hotelPoliciesDaoImpl.findAllHotelPolicies();
	}

	@Override
	public void saveAllHotelInfo(List<HotelInfo> hotelInfos) {
		hotelInfoDaoImpl.saveAllHotelInfo(hotelInfos);
		
	}

	@Override
	public void updateAllHotelInfo(List<HotelInfo> hotelInfos) {
		hotelInfoDaoImpl.updateAllHotelInfo(hotelInfos);
		
	}

	@Override
	public List<HotelInfo> findAllHotelInfo() {
		hotelInfoDaoImpl.findAllHotelInfo();
		return null;
	}

	@Override
	public void saveAllHotelImages(List<HotelImages> hotelImages) {
		hotelImagesDaoImpl.saveAllHotelImages(hotelImages);
	}

	@Override
	public void updateAllHotelImages(List<HotelImages> hotelImages) {
		hotelImagesDaoImpl.updateAllHotelImages(hotelImages);
	}

	@Override
	public List<HotelImages> findAllHotelImages() {
		return hotelImagesDaoImpl.findAllHotelImages();
	}

	@Override
	public void saveAllHotelDescription(List<HotelDescription> hotelDescriptions) {
		hotelDescriptionDaoImpl.saveAllHotelDescription(hotelDescriptions);
	}

	@Override
	public void updateAllHotelDescription(
			List<HotelDescription> HotelDescriptions) {
		hotelDescriptionDaoImpl.updateAllHotelDescription(HotelDescriptions);
	}

	@Override
	public List<HotelDescription> findAllHotelDescription() {
		return hotelDescriptionDaoImpl.findAllHotelDescription();
	}

	@Override
	public com.tmc.bean.inthotel.hotel.Hotel findHotelByHotelId(
			Integer hotelId) {
		return hotelDaoImpl.findHotelByHotelId(hotelId);
	}

	@Override
	public List<com.tmc.bean.inthotel.hotel.Hotel> findHotelByHotelName(
			String hotelName, String hotelNameCN,Integer source) {
		return hotelDaoImpl.findHotelByHotelName(hotelName, hotelNameCN,source);
	}
	
	@Override
	public void saveAllHotel(List<com.tmc.bean.inthotel.hotel.Hotel> hotels) {
		hotelDaoImpl.saveAllHotel(hotels);
	}

	@Override
	public List<com.tmc.bean.inthotel.hotel.Hotel> findAllHotel() {
		return hotelDaoImpl.findAllHotel();
	}

	@Override
	public void saveAllHotelAmenities(List<HotelAmenities> hotelAmenities) {
		hotelAmenitiesDaoImpl.saveAllHotelAmenities(hotelAmenities);
		
	}

	@Override
	public void updateAllHotelAmenities(List<HotelAmenities> hotelAmenities) {
		hotelAmenitiesDaoImpl.updateAllHotelAmenities(hotelAmenities);
		
	}

	@Override
	public List<HotelAmenities> findAllHotelAmenities() {
		return hotelAmenitiesDaoImpl.findAllHotelAmenities();
	}

	@Override
	public void saveAllCXLPolicies(List<CXLPolicies> cXLPolicies) {
		cXLPoliciesDaoImpl.saveAllCXLPolicies(cXLPolicies);
		
	}

	@Override
	public void updateAllCXLPolicies(List<CXLPolicies> cXLPolicies) {
		cXLPoliciesDaoImpl.updateAllCXLPolicies(cXLPolicies);
	}
	
	public String loadHotelData(String filePath){
		List<com.tmc.bean.inthotel.hotel.Hotel> hotels = saxHotelFromCvs(filePath);
		try {
			hotelDaoImpl.saveAllHotel(hotels);
			return "true";
		} catch (Exception e) {
			e.printStackTrace();
			return "false";
		}
	}
	
	public List<com.tmc.bean.inthotel.hotel.Hotel> saxHotelFromCvs(String filePath){
		BufferedReader br = cvsReader(filePath);
		List<com.tmc.bean.inthotel.hotel.Hotel> allString = new ArrayList<com.tmc.bean.inthotel.hotel.Hotel>();
		String line = "";
	    String urlLine = "";
	    try {
            while ((line = br.readLine()) != null)  //读取到的内容给line变量
            {
               // urlLine = new String(line.getBytes("gbk"),"UTF-8");
            	urlLine = line;
            	boolean isNum = urlLine.contains("0")||urlLine.contains("1")||urlLine.contains("2")||urlLine.contains("3")||urlLine.contains("4")||urlLine.contains("5")||urlLine.contains("6")||urlLine.contains("7")||urlLine.contains("8")||urlLine.contains("9");
                if(isNum){
                	String[] strs = urlLine.split("\\|");
                	/*for (int i = 0; i < strs.length; i++) {
						strs[i] = removeSpace(strs[i]).trim();
					}*/
                	System.out.println(strs[0]+"--"+strs[1]+"--"+strs[2]+"--"+strs[3]+"--"+strs[4]+"--"+strs[5]+"--"+strs[6]+"--"+strs[7]+"--"+strs[8]+"--"+strs[9]+"--"+strs[10]+"--"+strs[11]+"--"+strs[12]+"--"+strs[13]+"--"+strs[14]+"--"+strs[15]+"--"+strs[16]+"--"+strs[17]+"--"+strs[18]+"--"+strs[19]+"--"+strs[20]);
                	//System.out.println(strs[0]+"--"+strs[1]+"--"+strs[2]+"--"+strs[3]+"--"+strs[4]+"--"+strs[5]+"--"+strs[6]+"--"+strs[7]+"--"+strs[8]+"--"+strs[9]+"--"+strs[10]+"--"+strs[11]+"--"+strs[12]+"--"+strs[13]+"--"+strs[14]+"--"+strs[15]+"--"+strs[16]+"--"+strs[17]+"--"+strs[18]+"--"+strs[19]+"--"+strs[20]+"--"+strs[21]+"--"+strs[22]+"--"+strs[23]+"--"+strs[24]+"--"+strs[25]+"--"+strs[26]+"--"+strs[27]+"--"+strs[28]+"--"+strs[29]+"--"+strs[30]+"--"+strs[31]);
                	com.tmc.bean.inthotel.hotel.Hotel hotel = new com.tmc.bean.inthotel.hotel.Hotel();
                	hotel.setHotelId(Integer.valueOf(strs[0].replace("\"","")));
                	hotel.setHotelName(strs[1]);
                	hotel.setHotelNameCN(strs[2]);
                	hotel.setAddress(strs[3]);
                	hotel.setZipCode(strs[11]);
                	hotel.setHotelLatitude(strs[13]);
                	hotel.setHotelLongitude(strs[12]);
                	hotel.setStarRating(strs[14]);
                	hotel.setTelephone(strs[15]);
                	hotel.setAirportCode(strs[16]);
                	hotel.setAddressCity(strs[5]);
                	hotel.setCityCode(strs[4]);
                	hotel.setCityName(strs[5]);
                	hotel.setSource(2);
                	/*hotel.setStatus(strs[31]);
                	hotel.setLocation(strs[13]);*/
                	allString.add(hotel);
                }
            }
    } catch (Exception e)
    {
        e.printStackTrace();
    }
	    return allString;
	}
	
	/**
	 * 鏌ヨ鎵�鏈夐厭搴椾俊鎭�
	 */
	@Override
	public List<com.tmc.bean.inthotel.hotel.Hotel> getAllHotel() {
		return hotelDaoImpl.findAllHotel();
	}
	
	/**
	 * 鏇存柊鎵�鏈夐厭搴椾俊鎭�
	 * @param hotels
	 */
	public void updateAllHotel(List<com.tmc.bean.inthotel.hotel.Hotel> hotels){
		hotelDaoImpl.updateAllHotel(hotels);
	}
	
	public void updateHotelInfo(String f){
		List<com.tmc.bean.inthotel.hotel.Hotel> hotels = getAllHotel();
		List<com.tmc.bean.inthotel.hotel.Hotel> csvHotels = readCSVFile3(f);
		for (int i = 0; i < hotels.size(); i++) {
			com.tmc.bean.inthotel.hotel.Hotel hotel = hotels.get(i);
			int index = csvHotels.indexOf(hotel);
			if(index != -1){
				hotel.setHotelNameCN(csvHotels.get(index).getHotelNameCN());
			}
		}
		updateAllHotel(hotels);
	}
	
	public void updateHotelInfo1(){
		List<com.tmc.bean.inthotel.hotel.Hotel> hotels = getAllHotel();
		for (int i = 0; i < hotels.size(); i++) {
			com.tmc.bean.inthotel.hotel.Hotel hotel = hotels.get(i);
			if(hotel.getHotelNameCN()==null){
			  List<String> result =	SaxHtmlTest.sax(hotel.getHotelName());
			  if(result!=null && result.size()==2 && result.get(1).equalsIgnoreCase(hotel.getAddress())){
				  hotel.setHotelNameCN(result.get(0));
			  }
			}
		}
		updateAllHotel(hotels);
	}
	
	public static List<com.tmc.bean.inthotel.hotel.Hotel> readCSVFile3(String f)
	{
		File csv = new File(f);  // CSV鏂囦欢璺緞
	    FileInputStream fis = null;
	    InputStreamReader isr = null;
	    BufferedReader br = null;
	    List<com.tmc.bean.inthotel.hotel.Hotel> allString = new ArrayList<com.tmc.bean.inthotel.hotel.Hotel>();
	    try
	    {
	    	fis = new FileInputStream(csv);
	    	isr = new InputStreamReader(fis,"GBK");
	    	br = new BufferedReader(isr);
	    } catch (FileNotFoundException e)
	    {
	        e.printStackTrace();
	    } catch (Exception e) {
			e.printStackTrace();
		}
	    String line = "";
	    String urlLine = "";
	    try {
	            while ((line = br.readLine()) != null)  //读取到的内容给line变量
	            {
	                urlLine = line;
	                boolean isNum = urlLine.contains("0")||urlLine.contains("1")||urlLine.contains("2")||urlLine.contains("3")||urlLine.contains("4")||urlLine.contains("5")||urlLine.contains("6")||urlLine.contains("7")||urlLine.contains("8")||urlLine.contains("9");
	                if(isNum){
	                	String[] strs = urlLine.split("[|]");
	                	com.tmc.bean.inthotel.hotel.Hotel hotel = new com.tmc.bean.inthotel.hotel.Hotel();
	                	System.out.println(strs[0]+"--"+strs[1]+"--"+strs[2]);
	                	hotel.setHotelName(strs[1]);
	                	hotel.setHotelNameCN(strs[2]);
	                	allString.add(hotel);
	                }
	            }
	    } catch (IOException e)
	    {
	        e.printStackTrace();
	    }
	    return allString;
	}
	
	public void updateCityInfo(String filePath){
		List<com.tmc.bean.inthotel.hotel.City> cities = getAllCity();
		ArrayList<CityInfo> cityinfos = readCSVFile2(filePath);
	    for (int i = 0; i < cities.size(); i++) {
	    	com.tmc.bean.inthotel.hotel.City city = cities.get(i);
	    	int index = cityinfos.indexOf(city);
	    	if(index != -1){
	    		CityInfo cityInfo = cityinfos.get(index);
	    		city.setCityNameCN(cityInfo.getCityNameCn());
	    		city.setCityLongName(cityInfo.getCityName()+", "+cityInfo.getCountryName());
	    		city.setCityLongNameCN(cityInfo.getCityNameCn()+", "+cityInfo.getCountryNameCn());
	    	}
		}
	    cityDaoImpl.updateAllCity(cities);
	}
	
	/**
	 * 鏌ヨ鎵�鏈夊煄甯�
	 */
	@Override
	public List<com.tmc.bean.inthotel.hotel.City> getAllCity() {
		return cityDaoImpl.findAll();
	}
	
	public ArrayList<CityInfo> readCSVFile2(String filePath){
		File csv = new File(filePath);  // CSV鏂囦欢璺緞
	    FileInputStream fis = null;
	    InputStreamReader isr = null;
	    BufferedReader br = null;
	    ArrayList<CityInfo> allString = new ArrayList<CityInfo>();
	    try
	    {
	    	fis = new FileInputStream(csv);
	    	isr = new InputStreamReader(fis,"GBK");
	    	br = new BufferedReader(isr);
	    } catch (FileNotFoundException e)
	    {
	        e.printStackTrace();
	    } catch (Exception e) {
			e.printStackTrace();
		}
	    String line = "";
	    String urlLine = "";
	    try {
	            while ((line = br.readLine()) != null)  //读取到的内容给line变量
	            {
	                urlLine = line;
	                boolean isNum = urlLine.contains("0")||urlLine.contains("1")||urlLine.contains("2")||urlLine.contains("3")||urlLine.contains("4")||urlLine.contains("5")||urlLine.contains("6")||urlLine.contains("7")||urlLine.contains("8")||urlLine.contains("9");
	                if(isNum){
	                	String[] strs = urlLine.split("[|]");
	                	CityInfo cityInfo = new CityInfo();
	                	cityInfo.setCityName(strs[5]);
	                	cityInfo.setCityNameCn(strs[6]);
	                	cityInfo.setCountryName(strs[9]);
	                	cityInfo.setCountryNameCn(strs[10]);
	                	System.out.println(strs[5]+"--"+strs[6]+"--"+strs[9]+"--"+strs[10]);
	                	allString.add(cityInfo);
	                }
	            }
	    } catch (IOException e)
	    {
	        e.printStackTrace();
	    }
	    return allString;
	}
	
	/**
	 * 鏍规嵁鍥藉鍚嶇О鎼滅储澶ч檰
	 */
	@Override
	public String queryContient(String countryName) {
		return toCountryContientDaoImpl.queryContinent(countryName);
	}
	
	/**
	 * 鏍规嵁閰掑簵鍚嶆悳绱㈠尯鍩熶俊鎭�
	 */
	@Override
	public ToHotelTbl queryFromToHotelTbl(String hotelName) {
		return toHotelTblDaoImpl.getUniqueHotelInfo(hotelName);
	}
	
	/**
	 * 鎼滅储鎵�鏈夐厭搴椾俊鎭�
	 * @return
	 */
	public List<ToHotelTbl> queryAllHotelInfo(){
		return toHotelTblDaoImpl.getAllHotelInfo();
	}
	
	/**
	 * 鏍规嵁鍥藉鎼滅储澶ч檰鍚嶇О
	 * @param countryName
	 * @return
	 */
	public String queryContinent(String countryName){
		return toCountryContientDaoImpl.queryContinent(countryName);
	}
	
	public List<ToHotelTbl> readCSVFile1(String f){
	    File csv = new File(f);  // CSV鏂囦欢璺緞
	    FileInputStream fis = null;
	    InputStreamReader isr = null;
	    BufferedReader br = null;
	    List<ToHotelTbl> hotelTblList = new ArrayList<>();
	    try
	    {
	    	fis = new FileInputStream(csv);
	    	isr = new InputStreamReader(fis,"UTF-8");
	    	br = new BufferedReader(isr);
	    } catch (FileNotFoundException e)
	    {
	        e.printStackTrace();
	    } catch (Exception e) {
			e.printStackTrace();
		}
	    String line = "";
	    String urlLine = "";
	    String hotelName = "";
	    String cityName = "";
	    String countryName = "";
	    int index = 0;
	    try {
	            while ((line = br.readLine()) != null)  //读取到的内容给line变量
	            {
	                urlLine = line;
	                boolean isNum = urlLine.contains("0")||urlLine.contains("1")||urlLine.contains("2")||urlLine.contains("3")||urlLine.contains("4")||urlLine.contains("5")||urlLine.contains("6")||urlLine.contains("7")||urlLine.contains("8")||urlLine.contains("9");
	                if(isNum){
	                	String[] strs = urlLine.split("[|]");
	                	hotelName = removeSpace(strs[1].substring(3,strs[1].length()-2));
	                	if(strs[12].length()==1){
	                		cityName = removeSpace(strs[13].substring(3,strs[13].length()-2));
	                	}else{
	                		cityName = removeSpace(strs[12].substring(1,strs[12].length()-1));
	                	}
	                	countryName = removeSpace(strs[17].substring(3,strs[17].length()-2));
	                	ToHotelTbl hotelTbl = new ToHotelTbl();
	                	hotelTbl.setHotelName(hotelName);
	                	hotelTbl.setCityName(cityName);
	                	hotelTbl.setCountryName(countryName);
	                	String continentName = queryContinent(countryName);
	                	index++;
	                	log.info(hotelName+"--"+cityName+"--"+countryName+"--"+continentName+"------"+index);
	                	System.out.println(hotelName+"--"+cityName+"--"+countryName+"--"+continentName+"------"+index);
	                	hotelTbl.setContinentName(continentName);
	                	hotelTblList.add(hotelTbl);
	                }
	            }
	    } catch (IOException e){
	        e.printStackTrace();
	    }
	    return hotelTblList;
	}
	
	public List<String> saxCSV(String f,String hotelInfoPath){
		    File csv = new File(f);  // CSV鏂囦欢璺緞
		    FileInputStream fis = null;
		    InputStreamReader isr = null;
		    BufferedReader br = null;
		    List<String> saveHotelName = new ArrayList<>();
		    List<ToHotelTbl> list =readCSVFile1(hotelInfoPath);
		    try
		    {
		    	fis = new FileInputStream(csv);
		    	isr = new InputStreamReader(fis,"UTF-8");
		    	br = new BufferedReader(isr);
		    } catch (FileNotFoundException e)
		    {
		        e.printStackTrace();
		    } catch (Exception e) {
				e.printStackTrace();
			}
		    String line = "";
		    String urlLine = "";
		    String hotelNameLine = "";
		    int suc = 0;
		    int fail = 0;
		    int exist = 0;
		    
		    try {
		            while ((line = br.readLine()) != null)  //读取到的内容给line变量
		            {
		                urlLine = line;
		                boolean isNum = urlLine.contains("0")||urlLine.contains("1")||urlLine.contains("2")||urlLine.contains("3")||urlLine.contains("4")||urlLine.contains("5")||urlLine.contains("6")||urlLine.contains("7")||urlLine.contains("8")||urlLine.contains("9");
		                if(isNum){
		                	String[] strs = urlLine.split("[|]");
		                	hotelNameLine = strs[1].substring(3,strs[1].length()-3);
		                	hotelNameLine = removeSpace(hotelNameLine);
		                	ToHotelTbl hotelTbl = new ToHotelTbl();
		                	hotelTbl.setHotelName(hotelNameLine);
		                	int num = list.indexOf(hotelTbl);
		                	if(strs[2].indexOf("\"")==1){
		                		urlLine = strs[2].substring(strs[2].indexOf("\"")+2,strs[2].length()-2);
		                	}else{
		                		urlLine = strs[2].substring(1,strs[2].length()-2);
		                	}
		                	urlLine = removeSpace(urlLine);
		                	System.out.println(urlLine);
		                	String[] ss = urlLine.split("[/]");
		        			String fileName = ss[ss.length-1];
			                if(num!=-1){
			                	hotelTbl = list.get(num);
			                	hotelTbl.setHotelName(hotelNameLine.replace('&','@'));
			                	String result = sendInfo(urlLine,fileName, hotelTbl);
			                	hotelTbl.setHotelName(hotelNameLine);
			                	if(result.equals("true")){
			                		suc++;
			                		log.info(hotelNameLine+"涓婁紶鎴愬姛----"+suc);
			                		System.out.println(hotelNameLine+"涓婁紶鎴愬姛----"+suc);
			                	}else if(result.equals("exist")){
			                		exist++;
			                		log.info(hotelNameLine+"宸蹭笂浼�----"+exist);
			                		System.out.println(hotelNameLine+"宸蹭笂浼�----"+exist);
			                	}else{
			                		fail++; 
			                		saveHotelName.add(hotelNameLine);
			                		log.info(hotelNameLine+"涓婁紶杩囩▼寮傚父锛屼笂浼犲け璐�----"+fail);
			                		System.out.println(hotelNameLine+"涓婁紶杩囩▼寮傚父锛屼笂浼犲け璐�----"+fail);
			                		saveHotelName.add(hotelNameLine+":"+urlLine);
			                	}
			                }else{
			                	fail++;
			                	saveHotelName.add(hotelNameLine+":"+urlLine);
			                	log.info(hotelNameLine+"鍖归厤涓嶅埌鍖哄煙淇℃伅锛屼笂浼犲け璐�----"+fail);
			                	System.out.println(hotelNameLine+"鍖归厤涓嶅埌鍖哄煙淇℃伅锛屼笂浼犲け璐�----"+fail);
			                }
		                }
		            }
		    } catch (IOException e){
		        e.printStackTrace();
		    }
		    System.out.println("缁撴潫锛侊紒s");
		    return saveHotelName;
	}
	
	public static String removeSpace(String resource)   
    {   
        StringBuffer buffer=new StringBuffer();   
        int position=0;   
        int indexC = 0 ;
        int indexS = 0;
        String currentChar;   
        
        while(position<resource.length())   
        {   
            currentChar=resource.substring(position,position+1);
            position++;
            if(currentChar.matches("\\w|[:]|[/]|[.]|[&]|[-]|[(]|[)]|[%]|[*]|[']")){
            	buffer.append(currentChar);
            	indexC ++;
            }else{
            	indexS ++;
            }
            if(indexS>indexC){
            	buffer.append(" ");
            	indexS--;
            }
            
        } 
        return buffer.toString().replace("  "," ");   
    }  
	
	public String sendInfo(String imgUrl,String fileName,ToHotelTbl hotelTbl){
		String url = "http://192.168.4.201:8080/staticImgData/fileUpload/uploadImg/imageUpload";
		//String url = "http://localhost:8080/staticImgData/fileUpload/uploadImg/imageUpload";
		Map<String, String> mapParam = new HashMap<String, String>();
		mapParam.put("url",imgUrl);
		mapParam.put("fileName",fileName);
		mapParam.put("continentName",hotelTbl.getContinentName());
		mapParam.put("countryName",hotelTbl.getCountryName());
		mapParam.put("cityName",hotelTbl.getCityName());
		mapParam.put("hotelName",hotelTbl.getHotelName());
		String result = HttpUtil.sendPost(url, mapParam);
		return result;
	}
	
	/**
	 * 鑾峰彇鏍规嵁鍦板尯鎼滅储閰掑簵淇℃伅
	 */
	@Override
	public ToDestinationResult queryAllHotelByDestination() {
		ToDestinationResult destinationResult;
		Object obj =  getFromCache(TouricoHolidayServiceImpl.HOTEL_DESTINATION);
		if(obj!=null){
			destinationResult = (ToDestinationResult)obj;
		}else{
			destinationResult = toDestinationResultDaoImpl.findAllByDestinationResultId(9);
			putIntoCache(TouricoHolidayServiceImpl.HOTEL_DESTINATION,destinationResult);
		}
		return destinationResult;
	}
	
	/**
	 * 鑾峰彇destination淇℃伅
	 * @return
	 */
	public ToDestinationResult queryAllDestination(){
		ToDestinationResult destinationResult;
		Object obj =  getFromCache(TouricoHolidayServiceImpl.DESTINATION);
		if(obj!=null){
			destinationResult = (ToDestinationResult)obj;
		}else{
			destinationResult = toDestinationResultDaoImpl.findAllByDestinationResultId(4);
			putIntoCache(TouricoHolidayServiceImpl.DESTINATION,destinationResult);
		}
		return destinationResult;
	}
	
	/**
	 * 鏍规嵁detiantion鑾峰彇鍦板尯淇℃伅
	 * @return
	 */
	public ToDestinationResult queryAllActivitiesByDestination(){
		ToDestinationResult destinationResult;
		Object obj =  getFromCache(TouricoHolidayServiceImpl.ACTIVITY_DESTINATION);
		if(obj!=null){
			destinationResult = (ToDestinationResult)obj;
		}else{
			destinationResult = toDestinationResultDaoImpl.findAllByDestinationResultId(6);
			putIntoCache(TouricoHolidayServiceImpl.ACTIVITY_DESTINATION,destinationResult);
		}
		return destinationResult;
	} 
	
	public Object getFromCache(String key){
		return cache.get(TouricoHolidayServiceImpl.TOURICO_DATABASE,key);
	}
	
	public void putIntoCache(String key,Object value){
		cache.put(TouricoHolidayServiceImpl.TOURICO_DATABASE, key, value);
	}
	
	/**
	 * 鍩虹鏁版嵁
	 * 鑾峰彇鍦板尯淇℃伅
	 */
	@Override
	public DestinationResponse getDestination(Destination destination) {
		/*String url = "http://destservices.touricoholidays.com/DestinationsService.svc?wsdl";
		String requestStr = "http://touricoholidays.com/WSDestinations/2008/08/Contracts/IDestinationContracts/GetDestination";
		String xml = TouricoRequestXml.getDestinationXml(destination);
		String result = HttpUtil.wsdlRequest3(url,xml,requestStr);*/
		String fileName = "destinationResult1.xml";
		String result = XMLUtil.xmlChangeString(fileName);
		DestinationResponse resp= (DestinationResponse) XMLBeanUtil.convertXmlStrToObject(DestinationResponse.class,"DestinationResponse",result);
		/*ToDestinationResult toDest = new ToDestinationResult();
		copyDestinationResultProperties(resp.getDestinationResult(),toDest);
		toDestinationResultDaoImpl.save(toDest);
		System.out.println(JSON.toJSONString(toDest));*/
		return resp;
	}
	
	/**
	 * 鍩虹鏁版嵁
	 * 鏍规嵁鍦板尯鑾峰彇閰掑簵淇℃伅鍒楄〃
	 */
	@Override
	public HotelsByDestinationResponse getHotelsByDestination(
			Destination destination) {
		String url = "http://destservices.touricoholidays.com/DestinationsService.svc?wsdl";
		String requestStr = "http://touricoholidays.com/WSDestinations/2008/08/Contracts/IDestinationContracts/GetHotelsByDestination";
		String xml = TouricoRequestXml.getHotelsByDestinationXml(destination);
		String result = HttpUtil.wsdlRequest3(url,xml,requestStr);
		HotelsByDestinationResponse resp = (HotelsByDestinationResponse) XMLBeanUtil.convertXmlStrToObject(HotelsByDestinationResponse.class,"HotelsByDestinationResponse",result);
		/*ToDestinationResult toDest = new ToDestinationResult();
		copyDestinationResultProperties(resp.getDestinationResult(),toDest);
		toDestinationResultDaoImpl.save(toDest);*/
		return resp;
	}

	/**
	 * 鍩虹鏁版嵁
	 * 鏍规嵁鍖哄煙鑾峰彇鍦板潃淇℃伅鍒楄〃
	 */
	@Override
	public ActivitiesByDestinationResponse getActivitiesByDestination(
			Destination destination) {
		String url = "http://destservices.touricoholidays.com/DestinationsService.svc?wsdl";
		String requestStr = "http://touricoholidays.com/WSDestinations/2008/08/Contracts/IDestinationContracts/GetActivitiesByDestination";
		String xml = TouricoRequestXml.getActivitiesByDestination(destination);
		String result = HttpUtil.wsdlRequest3(url,xml,requestStr); 
		ActivitiesByDestinationResponse resp = (ActivitiesByDestinationResponse) XMLBeanUtil.convertXmlStrToObject(ActivitiesByDestinationResponse.class,"ActivitiesByDestinationResponse",result);
		/*ToDestinationResult toDest = new ToDestinationResult();
		copyDestinationResultProperties(resp.getDestinationResult(),toDest);
		toDestinationResultDaoImpl.save(toDest);
		System.out.println(JSON.toJSONString(toDest));*/
		return resp;
	}

	/**
	 * search
	 * 鏍规嵁閰掑簵id鎼滅储閰掑簵
	 */
	@Override
	public SearchHotelsByIdResponse searchHotelsById(
			SearchHotelsByIdRequest request, ArrayOfFeature features) {
		String url = "http://demo-hotelws.touricoholidays.com/HotelFlow.svc/bas";
		String requestStr = "http://tourico.com/webservices/hotelv3/IHotelFlow/SearchHotelsById";
		String xml = TouricoRequestXml.searchHotelsByIdXml(request, features);
		String result = HttpUtil.wsdlRequest3(url, xml, requestStr);
		return (SearchHotelsByIdResponse)XMLBeanUtil.convertXmlStrToObject(SearchHotelsByIdResponse.class,"SearchHotelsByIdResponse",result);
	}

	/**
	 * search
	 * 鏍规嵁鐩殑鍖哄煙鑾峰彇閰掑簵淇℃伅
	 */
	@Override
	public SearchHotelsByDestinationIdsResponse searchHotelsByDestinationIds(
			SearchHotelsByDestinationIdsRequest request, ArrayOfFeature features) {
		String url = "http://demo-hotelws.touricoholidays.com/HotelFlow.svc/bas";
		String requestStr = "http://tourico.com/webservices/hotelv3/IHotelFlow/SearchHotelsByDestinationIds";
		String xml = TouricoRequestXml.searchHotelsByDestinationIdsXml(request,features);
		String result = HttpUtil.wsdlRequest3(url, xml, requestStr);
		return (SearchHotelsByDestinationIdsResponse) XMLBeanUtil.convertXmlStrToObject(SearchHotelsByDestinationIdsResponse.class,"SearchHotelsByDestinationIdsResponse",result);
	}
	
	/**
	 * More Info
	 * 鑾峰彇閰掑簵璇︽儏
	 */
	@Override
	public String getHotelDetailsV3(ArrayOfHotelID hotelIds,
			ArrayOfFeature features) {
		String url = "http://demo-hotelws.touricoholidays.com/HotelFlow.svc/bas";
		String requestStr = "http://tourico.com/webservices/hotelv3/IHotelFlow/GetHotelDetailsV3";
		String xml = TouricoRequestXml.getHotelDetailsV3Xml(hotelIds,features);
		String result = HttpUtil.wsdlRequest3(url, xml, requestStr);
		String json = XMLUtil.convertHotelDetailXmlStrToJson("TWS_HotelDetailsV3",result);
		return json.replace("@","");
	}
	
	/**
	 * CLX Policy
	 * 鑾峰彇鍙栨秷棰勮鐨勮垂鐜�
	 */
	@Override
	public GetCancellationFeeResponse getCancellationFee(int nResID,
			XMLGregorianCalendar clxDate) {
		String url = "http://demo-hotelws.touricoholidays.com/HotelFlow.svc/bas";
		String requestStr = "http://tourico.com/webservices/hotelv3/IHotelFlow/GetCancellationFee";
		String xml = TouricoRequestXml.getCancellationFeeXml(nResID, clxDate);
		String result = HttpUtil.wsdlRequest3(url, xml, requestStr);
		return (GetCancellationFeeResponse)XMLBeanUtil.convertXmlStrToObject(GetCancellationFeeResponse.class,"GetCancellationFeeResponse",result);
	}

	/**
	 * CLX Policy
	 * 鍙栨秷棰勮
	 */
	@Override
	public CancelReservationResponse cancelReservation(int nResID) {
		String url = "http://demo-wsnew.touricoholidays.com/ReservationsService.asmx";
		String requestStr = "http://tourico.com/webservices/CancelReservation";
		String xml = TouricoRequestXml.CancelReservationXml(nResID);
		String result = HttpUtil.wsdlRequest3(url, xml, requestStr);
		return (CancelReservationResponse)XMLBeanUtil.convertXmlStrToObject(CancelReservationResponse.class,"CancelReservationResponse",result);
	}
	
	/**
	 * CLX Policy
	 * 鑾峰彇鍙栨秷棰勮鏀跨瓥淇℃伅
	 */
	@Override
	public GetCancellationPoliciesResponse getCancellationPolicies(Integer choose,int nResId,
			int hotelId, int hotelRoomTypeId,
			XMLGregorianCalendar dtCheckIn, XMLGregorianCalendar dtCheckOut) {
		String url = "http://demo-hotelws.touricoholidays.com/HotelFlow.svc/bas";
		String requestStr = "http://tourico.com/webservices/hotelv3/IHotelFlow/GetCancellationPolicies";
		String xml = TouricoRequestXml.getCancellationPoliciesXml(choose,nResId, hotelId, hotelRoomTypeId,dtCheckIn,dtCheckOut);
		String result = HttpUtil.wsdlRequest3(url, xml, requestStr);
		return (GetCancellationPoliciesResponse)XMLBeanUtil.convertXmlStrToObject(GetCancellationPoliciesResponse.class,"GetCancellationPoliciesResponse",result);
	}
	
	/**
	 * Verification
	 * 鏍稿疄閰掑簵浠锋牸鍙婃槸鍚﹀彲鐢�
	 */
	@Override
	public CheckAvailabilityAndPricesResponse checkAvailabilityAndPrices(
			SearchHotelsByIdRequest request,ArrayOfFeature features) {
		String url = "http://demo-hotelws.touricoholidays.com/HotelFlow.svc/bas";
		String requestStr = "http://tourico.com/webservices/hotelv3/IHotelFlow/CheckAvailabilityAndPrices";
		String xml = TouricoRequestXml.checkAvailabilityAndPricesXml(request, features);
		String result = HttpUtil.wsdlRequest3(url, xml, requestStr);
		return (CheckAvailabilityAndPricesResponse)XMLBeanUtil.convertXmlStrToObject(CheckAvailabilityAndPricesResponse.class,"CheckAvailabilityAndPricesResponse",result) ;
	}
	
	/**
	 * Book
	 * 棰勮閰掑簵
	 */
	@Override
	public BookHotelV3Response bookHotelV3(BookV3Request request,
			ArrayOfFeature features) {
		String url = "http://demo-hotelws.touricoholidays.com/HotelFlow.svc/bas";
		String requestStr = "http://tourico.com/webservices/hotelv3/IHotelFlow/BookHotelV3";
		String xml = TouricoRequestXml.bookHotelV3Xml(request, features);
		String result = HttpUtil.wsdlRequest3(url, xml, requestStr);
		return (BookHotelV3Response)XMLBeanUtil.convertXmlStrToObject(BookHotelV3Response.class,"BookHotelV3Response",result);
	}

	/**
	 * Book
	 * 淇敼棰勮娑堣垂
	 */
	@Override
	public CostAmendResponse costAmend(CostAmendRequest request,
			ArrayOfFeature features) {
		String url = "http://demo-hotelws.touricoholidays.com/HotelFlow.svc/bas";
		String requestStr = "http://tourico.com/webservices/hotelv3/IHotelFlow/CostAmend";
		String xml = TouricoRequestXml.costAmendXml(request, features);
		String result = HttpUtil.wsdlRequest3(url, xml, requestStr);
		return (CostAmendResponse)XMLBeanUtil.convertXmlStrToObject(CostAmendResponse.class,"CostAmendResponse",result);
	}

	/**
	 * Book
	 * 纭淇敼淇℃伅
	 */
	@Override
	public DoAmendResponse doAmend(AmendRequest request, ArrayOfFeature features) {
		String url = "http://demo-hotelws.touricoholidays.com/HotelFlow.svc/bas";
		String requestStr = "http://tourico.com/webservices/hotelv3/IHotelFlow/DoAmend";
		String xml = TouricoRequestXml.doAmendXml(request, features);
		String result = HttpUtil.wsdlRequest3(url, xml, requestStr);
		return (DoAmendResponse)XMLBeanUtil.convertXmlStrToObject(DoAmendResponse.class,"DoAmendResponse",result);
	}

	/**
	 * copy destinationResult
	 * @param resource
	 * @param target
	 */
	public void copyDestinationResultProperties(DestinationResult resource,ToDestinationResult target){
		try {
			target.setCulture(resource.getCulture());
			target.setResultNum(resource.getResultNum());
			target.setServerTime(resource.getServerTime());
			target.setVersion(resource.getVersion());
			target.setLastUpdateDate(DateUtil.format("2017-04-26","yyyy-MM-dd"));
			List<Continent> conList = resource.getContinent();
			Set<ToContinent> continentSet = new HashSet<ToContinent>();
			for (int i = 0; i < conList.size(); i++) {
				ToContinent toCon = new ToContinent();
				Continent con= conList.get(i);
				copyContinentProperties(con, toCon,target);
				continentSet.add(toCon);
			}
			target.setToContinents(continentSet);
		} catch (ParseException e) {
			e.printStackTrace();
		}
	}

	/**
	 * copy continent
	 * @param resource
	 * @param target
	 * @param toDestinationResult
	 */
	public void copyContinentProperties(Continent resource,ToContinent target,ToDestinationResult toDestinationResult){
		target.setContinentName(resource.getName());
		target.setContinentProvider(resource.getProvider());
		target.setContinentStatus(resource.getStatus());
		target.setElementType(resource.getElementType());
		target.setToDestinationResult(toDestinationResult);
		List<Country> couList = resource.getCountry();
		Set<ToCountry> toCouSet = new HashSet<ToCountry>();
		for (int i = 0; i < couList.size(); i++) {
			ToCountry toCou = new ToCountry();
			Country cou = couList.get(i);
			copyCountryProperties(cou,toCou,target);
			toCouSet.add(toCou);
		}
		target.setToCountries(toCouSet);
	}
	
	/**
	 * copy country
	 * @param resource
	 * @param target
	 * @param toContinent
	 */
	public void copyCountryProperties(Country resource,ToCountry target,ToContinent toContinent){
		target.setCountryName(resource.getName());
		target.setCountryProvider(resource.getProvider());
		target.setCountryStatus(resource.getStatus());
		target.setElementType(resource.getElementType());
		target.setToContinent(toContinent);
		List<State> staList = resource.getState();
		Set<ToState> toStaSet = new HashSet<ToState>();
		for (int i = 0; i < staList.size(); i++) {
			ToState toSta = new ToState();
			State state = staList.get(i);
			copyStateProperties(state, toSta,target);
			toStaSet.add(toSta);
		}
		target.setToStates(toStaSet);
	}
	
	/**
	 * copy state
	 * @param resource
	 * @param target
	 * @param toCountry
	 */
	public void copyStateProperties(State resource,ToState target,ToCountry toCountry){
		target.setStateName(resource.getName());
		target.setStateProvider(resource.getProvider());
		target.setStateShort(resource.getStateShort());
		target.setStateStatus(resource.getStatus());
		target.setElementType(resource.getElementType());
		target.setToCountry(toCountry);
		List<City> cityList = resource.getCity();
		Set<ToCity> toCitySet = new HashSet<ToCity>();
		for (int i = 0; i <cityList.size(); i++) {
			ToCity toCity = new ToCity();
			City city = cityList.get(i);
			copyCityProperties(city, toCity, target);
			toCitySet.add(toCity);
		}
		target.setToCities(toCitySet);
	}
	
	/**
	 * copy city
	 * @param resource
	 * @param target
	 * @param toState
	 */
	public void copyCityProperties(City resource,ToCity target,ToState toState){
		target.setCityLatitude(resource.getCityLatitude());
		target.setCityLongitude(resource.getCityLongitude());
		target.setCityName(resource.getName());
		target.setCityProvider(resource.getProvider());
		target.setCityStatus(resource.getStatus());
		target.setDestinationCode(resource.getDestinationCode());
		target.setElementType(resource.getElementType());
		target.setToState(toState);
		if(resource.getHotels()!=null){
			List<Hotel> hotList = resource.getHotels().getHotel();
			Set<ToHotel> toHotelSet = new HashSet<ToHotel>();
			for (int i = 0; i < hotList.size(); i++) {
				ToHotel toHotel = new ToHotel();
				Hotel hotel = hotList.get(i);
				copyHotelProperties(hotel, toHotel,target,null);
				toHotelSet.add(toHotel);
			}
			target.setToHotels(toHotelSet);
		}
		if(resource.getActivities()!=null){
			List<Activity> actList = resource.getActivities().getActivity();
			Set<ToActivity> toActSet = new HashSet<ToActivity>();
			for (int i = 0; i < actList.size(); i++) {
				ToActivity toAct = new ToActivity();
				Activity act = actList.get(i);
				copyActivityProperties(act, toAct, target,null);
				toActSet.add(toAct);
			}
			target.setToActivities(toActSet);
		}
		if(resource.getCityLocation()!=null){
			List<CityLocation> cityLocList = resource.getCityLocation();
			Set<ToCitylocation> toCityLocSet = new HashSet<ToCitylocation>();
			for (int i = 0; i < cityLocList.size(); i++) {
				ToCitylocation toCityLoc = new ToCitylocation();
				CityLocation cityLoc = cityLocList.get(i);
				copyCityLocationProperties(cityLoc,toCityLoc,target);
				toCityLocSet.add(toCityLoc);
			}
			target.setToCitylocations(toCityLocSet);
		}
		
	}
	
	/**
	 * copy hotel
	 * @param resource
	 * @param target
	 * @param toCity
	 * @param toCityLoc
	 */
	public void copyHotelProperties(Hotel resource,ToHotel target,ToCity toCity,ToCitylocation toCityLoc){
		if(resource !=null){
			target.setAddress(resource.getAddress());
			target.setCity(resource.getCity());
			target.setCountryCode(resource.getCountryCode());
			target.setDestinationCode(resource.getDestinationCode());
			target.setDestinationId(resource.getDestinationId());
			target.setHotelLatitude(resource.getHotelLatitude());
			target.setHotelLongitude(resource.getHotelLongitude());
			target.setHotelName(resource.getHotelName());
			target.setLocation(resource.getLocation());
			target.setStars(resource.getStars());
			target.setState(resource.getState());
			target.setStateCode(resource.getStateCode());
			target.setStatus(resource.getStatus());
			target.setZip(resource.getZip());
			target.setToCity(toCity);
			target.setToCitylocation(toCityLoc);
		}
	}
	
	/**
	 * copy activity
	 * @param resource
	 * @param target
	 * @param toCity
	 * @param toCityLoc
	 */
	public void copyActivityProperties(Activity resource,ToActivity target,ToCity toCity,ToCitylocation toCityLoc){
		if(resource!=null){
			target.setActivityCategory(resource.getActivityCategory());
			target.setActivityCategoryId(resource.getActivityCategoryID());
			target.setActivityLatitude(resource.getActivityLatitude());
			target.setActivityLongitude(resource.getActivityLongitude());
			target.setActivityName(resource.getActivityName());
			target.setAddress(resource.getAddress());
			target.setBestVal(Integer.valueOf(resource.getBestVal()+""));
			target.setCity(resource.getCity());
			target.setCountryCode(resource.getCountryCode());
			target.setDestinationCode(resource.getDestinationCode());
			target.setDestinationId(resource.getDestinationId());
			target.setStars(resource.getStars());
			target.setStatus(resource.getStatus());
			target.setZip(resource.getZip());
			target.setToCity(toCity);
			target.setToCitylocation(toCityLoc);
		}
	}
	
	/**
	 * copy cityLocation
	 * @param resource
	 * @param target
	 * @param toCity
	 */
	public void copyCityLocationProperties(CityLocation resource,ToCitylocation target,ToCity toCity){
		if(resource !=null){
			target.setCity(resource.getCity());
			target.setCityDestinationId(resource.getCityDestinationId());
			target.setCityLocationProvider(resource.getProvider());
			target.setCityLocationStatus(resource.getStatus());
			target.setDestinationCode(resource.getDestinationCode());
			target.setLocation(resource.getLocation());
			target.setToCity(toCity);
			if(resource.getHotels()!=null){
				List<Hotel> hotList = resource.getHotels().getHotel();
				Set<ToHotel> toHotelSet = new HashSet<ToHotel>();
				for (int i = 0; i < hotList.size(); i++) {
					ToHotel toHotel = new ToHotel();
					Hotel hotel = hotList.get(i);
					copyHotelProperties(hotel, toHotel,null,target);
					toHotelSet.add(toHotel);
				}
				target.setToHotels(toHotelSet);
			}
			if(resource.getActivities()!=null){
				List<Activity> actList = resource.getActivities().getActivity();
				Set<ToActivity> toActSet = new HashSet<ToActivity>();
				for (int i = 0; i < actList.size(); i++) {
					ToActivity toAct = new ToActivity();
					Activity act = actList.get(i);
					copyActivityProperties(act, toAct,null,target);
					toActSet.add(toAct);
				}
				target.setToActivities(toActSet);
			}
			Set<ToProvider> toProSet = new HashSet<ToProvider>();
			ToProvider toPro = new ToProvider();
			toPro.setProviderValue(resource.getProvider());
			toProSet.add(toPro);
		}
	}

	public static void main(String[] args) {
		/*String s = "0";
		System.out.println(s.matches("\\d+"));*/
		try {
			DateUtil.format("","yyyy-MM-dd");
		} catch (ParseException e) {
			e.printStackTrace();
		}
	}

	@Override
	public SearchHotelsResponse searchHotels(SearchRequest request,
			ArrayOfFeature features) {
		String url = "http://demo-hotelws.touricoholidays.com/HotelFlow.svc/bas";
		String requestStr = "http://tourico.com/webservices/hotelv3/IHotelFlow/SearchHotels";
		String xml = TouricoRequestXml.searchHotelsXml(request, features);
		String result = HttpUtil.wsdlRequest3(url, xml, requestStr);
		return (SearchHotelsResponse)XMLBeanUtil.convertXmlStrToObject(SearchHotelsResponse.class,"SearchHotelsResponse",result);
	}

}
